package com.edu.exam.entity.quality.workflow;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.hibernate.annotations.Comment;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import jakarta.persistence.*;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Size;
import java.math.BigDecimal;
import java.time.LocalDateTime;

/**
 * 审核监控实体类
 * 对应数据库表：audit_monitor
 *
 * 根据B-02-05试题审核流程子模块设计文档实现
 * 管理审核监控数据，支持流程、任务、规则三种监控类型。
 *
 * @author System
 * @version 1.0.0
 */
@Entity
@Table(name = "audit_monitor")
@Comment("审核监控表")
@EntityListeners(AuditingEntityListener.class)
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class AuditMonitor {

    /**
     * 主键ID
     */
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "id")
    private Long id;

    /**
     * 审核监控唯一标识符
     */
    @NotBlank(message = "审核监控ID不能为空")
    @Size(max = 50, message = "审核监控ID长度不能超过50个字符")
    @Column(name = "monitor_id", nullable = false, length = 50, unique = true)
    private String monitorId;

    /**
     * 监控对象ID（流程实例ID、任务ID、规则ID等）
     */
    @NotBlank(message = "监控对象ID不能为空")
    @Size(max = 50, message = "监控对象ID长度不能超过50个字符")
    @Column(name = "target_id", nullable = false, length = 50)
    private String targetId;

    /**
     * 监控类型（FLOW-流程监控，TASK-任务监控，RULE-规则监控）
     */
    @NotBlank(message = "监控类型不能为空")
    @Size(max = 20, message = "监控类型长度不能超过20个字符")
    @Column(name = "monitor_type", nullable = false, length = 20)
    private String monitorType;

    /**
     * 指标名称
     */
    @NotBlank(message = "指标名称不能为空")
    @Size(max = 100, message = "指标名称长度不能超过100个字符")
    @Column(name = "metric_name", nullable = false, length = 100)
    private String metricName;

    /**
     * 指标值
     */
    @Column(name = "metric_value", precision = 15, scale = 4)
    private BigDecimal metricValue;

    /**
     * 指标单位
     */
    @Size(max = 20, message = "指标单位长度不能超过20个字符")
    @Column(name = "metric_unit", length = 20)
    private String metricUnit;

    /**
     * 基准值（用于比较）
     */
    @Column(name = "baseline_value", precision = 15, scale = 4)
    private BigDecimal baselineValue;

    /**
     * 阈值上限
     */
    @Column(name = "threshold_upper", precision = 15, scale = 4)
    private BigDecimal thresholdUpper;

    /**
     * 阈值下限
     */
    @Column(name = "threshold_lower", precision = 15, scale = 4)
    private BigDecimal thresholdLower;

    /**
     * 告警级别（NORMAL-正常，WARNING-警告，ERROR-错误，CRITICAL-严重）
     */
    @Size(max = 20, message = "告警级别长度不能超过20个字符")
    @Column(name = "alert_level", length = 20)
    private String alertLevel;

    /**
     * 告警消息
     */
    @Size(max = 500, message = "告警消息长度不能超过500个字符")
    @Column(name = "alert_message", length = 500)
    private String alertMessage;

    /**
     * 监控时间
     */
    @NotNull(message = "监控时间不能为空")
    @Column(name = "monitor_time", nullable = false)
    private LocalDateTime monitorTime;

    /**
     * 监控维度（JSON格式）
     */
    @Column(name = "monitor_dimensions", columnDefinition = "TEXT")
    private String monitorDimensions;

    /**
     * 监控标签（JSON格式）
     */
    @Column(name = "monitor_tags", columnDefinition = "TEXT")
    private String monitorTags;

    /**
     * 监控配置（JSON格式）
     */
    @Column(name = "monitor_config", columnDefinition = "TEXT")
    private String monitorConfig;

    /**
     * 创建者ID
     */
    @Size(max = 50, message = "创建者ID长度不能超过50个字符")
    @Column(name = "created_by", nullable = false, length = 50)
    private String createdBy;

    /**
     * 创建时间
     */
    @CreatedDate
    @Column(name = "create_time", nullable = false, updatable = false)
    private LocalDateTime createTime;

    /**
     * 更新时间
     */
    @Column(name = "update_time", nullable = false)
    private LocalDateTime updateTime;

    /**
     * 软删除标识
     */
    @NotNull(message = "软删除标识不能为空")
    @Column(name = "is_deleted", nullable = false)
    private Boolean isDeleted;

    /**
     * 删除时间
     */
    @Column(name = "delete_time")
    private LocalDateTime deleteTime;

    /**
     * 更新人
     */
    @Size(max = 50, message = "更新人长度不能超过50个字符")
    @Column(name = "updated_by", nullable = false, length = 50)
    private String updatedBy;

}